package com.konsung.ksdc.common.network;

import android.annotation.TargetApi;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.widget.Toast;

import com.google.gson.Gson;
import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.netbean.ContactRequestNetBean;
import com.konsung.ksdc.bean.netbean.RegisterEmpNetBean;
import com.konsung.ksdc.config.MyApplication;
import com.konsung.ksdc.config.NetConfig;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * Created by Administrator on 2016/3/17 0017.
 */
public class RequestUtils {

    /**
     * 判断网络是否已连接
     * @param context 上下文
     * @return boolean true:有网络连接 false:没有网络连接
     */
    public static boolean isNetworkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager)
                    context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager
                    .getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }
        return false;
    }

    /**
     * 判断wifi是否链接可以使用
     * @param mContext 上下文
     * @return 是否wifi连接
     */
    public static boolean isWifiAvailable(Context mContext) {
        ConnectivityManager connectivityManager = (ConnectivityManager)
                mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            android.net.NetworkInfo wifi = connectivityManager.getNetworkInfo(ConnectivityManager
                    .TYPE_WIFI);

            return wifi.isAvailable();
        }
        return false;
    }

    /**
     * 判断移动网络是否链接可以使用
     * @param mContext 上下文
     * @return 手机是否连接
     */
    public static boolean isMobileAvailable(Context mContext) {
        ConnectivityManager connectivityManager = (ConnectivityManager)
                mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetInfo != null && activeNetInfo.getType() ==
                ConnectivityManager.TYPE_MOBILE) {
            android.net.NetworkInfo mobile = connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

            return mobile.isAvailable();
        }
        return false;
    }

    /**
     * 检查网络连接 给出提示
     * @param context 上下文
     * @return bolean true:有网络连接 false:没有网络连接
     */
    public static boolean checkNetwork(Context context) {
        if (!isNetworkConnected(context)) {
            Toast.makeText(context, R.string.tip_check_net, Toast
                    .LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

    /**
     * 登录接口
     * @param name 用户名
     * @param pwd 密码
     * @param deviceCode 验证码
     * @param callback 用户登录使用的回调 需要自己创建对象，处理回调
     */
    public static void login(String name, String pwd, String deviceCode,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "applogin";
        OkHttpUtils
                .post()
                .url(url)
                .addParams("username", name)
                .addParams("password", pwd)
                .addParams("deviceCode", deviceCode)
                .build()
                .execute(callback);
    }

    /**
     * @param bean 要传递给服务器注册用的用户bean
     * @param callback 用户注册使用的回调 需要自己创建对象，处理回调
     */
    public static void register(RegisterEmpNetBean bean, RequestCallback
            callback) {
        String url = NetConfig.getBasicUrl() + "register";
        String registerData = new Gson().toJson(bean);
        OkHttpUtils
                .post()
                .url(url)
                .addParams("registerData", registerData)
                .build()
                .execute(callback);
    }

    /**
     * 同步查询联系人列表
     * @param userId 用户id
     * @return 响应数据
     * @throws Exception 异常
     */
    public static Response findContacts(String userId) throws Exception {
        String url = NetConfig.getBasicUrl() + "findUserContacts";

        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", userId);

        Request request = buildSyscPostRequest(url, params);

        OkHttpClient client = new OkHttpClient();
        return client.newCall(request).execute();
    }

    /**
     * 查找联系人
     * @param condition 条件
     * @param callback 回调
     */
    public static void findContactsByCondition(String condition,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "findContactsByCondition";
        OkHttpUtils
                .post()
                .url(url)
                .addParams("condition", condition)
                .build()
                .execute(callback);
    }

    /**
     * 获取验证码的接口
     * @param phone 手机号码
     * @param randowCode 要发送的验证码
     */
    public static void getCheckCode(String phone, String randowCode) {
        String url = "http://utf8.sms.webchinese" +
                ".cn/?Uid=kuang5706316&Key=8d7694e5eb279cf6fe33&smsMob=" +
                phone + "&smsText"
                + "=" + "验证码:" + randowCode;

//        http://utf8.sms.webchinese
// .cn/?Uid=本站用户名&Key=接口安全秘钥&smsMob=手机号码&smsText=验证码8888

        OkHttpUtils
                .post()
                .url(url)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response) throws Exception {
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        Toast.makeText(MyApplication.getContext(),
                                R.string.tip_server_error, Toast
                                        .LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(Object o) {
                    }
                });
    }

    /**
     * 查询用户所关联的一体机列表
     * @param empId 用户ID
     * @param callback 回调
     */
    public static void findRelatedMac(String empId, RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "findUserRelateMac";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("empId", empId)
                .build()
                .execute(callback);
    }

    /**
     * 查询所给定的序列号是否合法(服务器是否有该一体机的信息)
     * @param searialNum 序列号
     * @param callback 回调
     */
    public static void findMachineBySearialNum(String searialNum,
            RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "findMachineBySearialNum";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("searialNum", searialNum)
                .build()
                .execute(callback);
    }

    /**
     * 关联一体机
     * @param empId 用户ID
     * @param macId 一体机ID
     * @param callback 回调
     */
    public static void relateMac(String empId, String macId,
            RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "relateMac";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("empId", empId)
                .addParams("macId", macId)
                .build()
                .execute(callback);
    }

    /**
     * 解除一体机的关联
     * @param empId 用户ID
     * @param macId 一体机ID
     * @param callback 回调
     */
    public static void derelateMac(String empId, String macId,
            RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "derelateMac";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("empId", empId)
                .addParams("macId", macId)
                .build()
                .execute(callback);
    }

    /**
     * 根据用户ID获取售后列表信息
     * @param empId 用户ID
     * @param callback 回调
     */
    public static void findSaleServiceByEmpId(String empId,
            RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "findSaleServiceByEmpId";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("empId", empId)
                .build()
                .execute(callback);
    }

    /**
     * 根据ServiceID(查询售后列表会返回)查询该条目详情
     * @param serviceId 服务id
     * @param callback 回调
     */
    public static void findDetailById(String serviceId, RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "findDetailById";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("serviceId", serviceId)
                .build()
                .execute(callback);
    }

    /**
     * 上传文件(图片)
     * @param file 文件对象
     * @param callback 回调
     */
    public static void uploadPicture(File file, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "uploadPicture";

        OkHttpUtils
                .post()
                .addFile("file", "test+" + System.currentTimeMillis() + ".jpg", file)
                .url(url)
                .build()//
                .execute(callback);
    }

    /**
     * 上传数据
     * @param requestEmpId 请求的用户ID
     * @param requestMacId 请求的机器ID
     * @param serviceContent 问题描述
     * @param picPath 上传的图片路径
     * @param callback 回调
     */
    public static void saveSaleService(String requestEmpId, String
            requestMacId, String serviceContent, String picPath,
            RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "saveSaleService";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("requestEmpId", requestEmpId)
                .addParams("requestMacId", requestMacId)
                .addParams("serviceContent", serviceContent)
                .addParams("picPath", picPath)
                .build()
                .execute(callback);
    }

    /**
     * 查询所有意见与建议
     * @param empId 所查询用户的ID
     * @param callback 回调
     */
    public static void findSuggestionByEmpId(String empId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "findSuggestionByEmpId";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("empId", empId)
                .build()
                .execute(callback);
    }

    /**
     * 提交意见与建议
     * @param requestEmpId 用户id
     * @param suggestionContent 意见与建议内容
     * @param callback 回调
     */
    public static void commitSuggestion(String requestEmpId, String
            suggestionContent, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "saveSuggestion";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("requestEmpId", requestEmpId)
                .addParams("suggestionContent", suggestionContent)
                .build()
                .execute(callback);
    }

    /**
     * 发送用户习惯数据
     * @param statDesc 页面的描述
     * @param empId 用户ID
     * @param beginDate 进入时间
     * @param endDate 退出时间
     * @param operType 操作类型
     * @param callback 回调
     */

    public static void commitUserData(String statDesc, String empId, String beginDate,
            String endDate, String operType, RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "saveUserStat";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("statDesc", statDesc)
                .addParams("empId", empId)
                .addParams("beginDate", beginDate)
                .addParams("endDate", endDate)
                .addParams("operType", operType)
                .build()
                .execute(callback);
    }

    /**
     * 查询推送信息
     * @param callback 回调
     */
    public static void findMessagePush(RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "findMessagePush";

        OkHttpUtils
                .post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 查询更新信息
     * @param callback 回调
     */
    public static void findUpgradeMessage(RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "findUpgradeMessage";

        OkHttpUtils
                .post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 下载最新版本APK文件
     * @param apkName apk名称
     * @param cacheSize 缓存
     * @param callback 回调
     */
    public static void downloadApk(String apkName, String cacheSize, MyFileCallBack callback) {
        String url = NetConfig.getRootUrl() + "download/downloadFile";
        OkHttpUtils
                .get()
                .addParams("fileName", apkName)
                .addParams("rRange", cacheSize + "-")
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 通过用户名，查询绑定的手机号
     * @param phone 用户名
     * @param callback 回调
     */
    public static void findTelephone(String phone, RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "findTelephone";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("phone", phone)
                .build()
                .execute(callback);
    }

    /**
     * 传递帐号和新密码来修改密码
     * @param userPhone 手机号
     * @param password 密码
     * @param callback 回调
     */
    public static void updatePassword(String userPhone, String password, RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "updatePassword";

        OkHttpUtils
                .post()
                .url(url)
                .addParams("userPhone", userPhone)
                .addParams("password", password)
                .build()
                .execute(callback);
    }

    /**
     * 修改绑定手机
     * @param empId 用户帐号
     * @param phone 新的绑定手机号
     * @param callback 回调
     */
    public static void updateTelephone(String empId, String phone, RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "updateTelephone";
        OkHttpUtils
                .post()
                .url(url)
                .addParams("empId", empId)
                .addParams("phone", phone)
                .build()
                .execute(callback);
    }

    /**
     * 获取轮播图数据
     * @param callback 回调
     */
    public static void findCarouselImages(RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "findCarouselImages";

        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 获取所有产品数据
     * @param callback 回调
     */
    public static void findAllProducts(RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "findAllProducts";
//        String url = NetConfig.getBasicUrl() + "findAllProducts";
        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 获取产品详情数据
     * @param callback 回调
     * @param productId id
     */
    public static void findProductDetailById(String productId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "findProductDetailById?id=" +
                productId;

        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 发送添加至购物车的请求
     * @param memberId num比例
     * @param productId 产品id
     * @param shopNumber 号码数字
     * @param callback 回调
     */
    public static void add2ShoppingCart(String memberId, String productId, String shopNumber,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() +
                "addShoppingCat?" +
                "memberId=" + memberId +
                "&productId=" + productId +
                "&shopNumber=" + shopNumber;

        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 查看购物车详情（列表）
     * @param callback 回调
     * @param memberId 会员id
     */
    public static void showCatDetail(String memberId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() +
                "showCatDetail?" + "memberId=" + memberId;

        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 发送从购物车删除的请求
     * @param callback 回调
     * @param catId 购物车id
     */
    public static void deleteCatById(String catId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "deleteCatById?" +
                "catId=" + catId;

        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 批量删除购物车商品
     * @param callback 回调
     * @param catIds 购物车商品id拼接
     */
    public static void deleteCatByIds(String catIds, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "deleteCatByIds?" +
                "catIds=" + catIds;

        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 发送更新购物车的请求
     * @param map 集合
     * @param callback 回调
     */
    @TargetApi(Build.VERSION_CODES.KITKAT)
    public static void updateCat(Map<String, String> map, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() +
                "updateCat?value=";

        StringBuilder builder = new StringBuilder();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            builder.append(entry.getKey()).append("-")
                    .append(entry.getValue()).append(";");
        }
        String data = builder.toString();
        url = url + data;

        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 添加或编辑联系人地址（根据是否有id）
     * @param id address id 如果是新增 就为空  修改就传address的id
     * @param userName 用户id
     * @param phone 号码
     * @param memberId 会员id
     * @param provinceCode 职权id
     * @param provinceName 职权名称
     * @param cityCode 城市代码
     * @param cityName 城市名称
     * @param townCode 小镇
     * @param townName 小镇名称
     * @param surplusAddress 上一级地址
     * @param detailAddress 详细地址
     * @param postalCode 邮编
     * @param isTactly 法律
     * @param callback 回调
     */
    public static void saveOrUpdateAddress(String id, String userName,
            String phone, String memberId,
            String provinceCode,
            String provinceName,
            String cityCode, String cityName,
            String townCode, String townName,
            String surplusAddress,
            String detailAddress,
            String postalCode, String isTactly,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "saveOrUpdateAddress?";
        OkHttpUtils.post()
                .url(url)
                .addParams("id", id)
                .addParams("username", userName)
                .addParams("phone", phone)
                .addParams("memberId", memberId)
                .addParams("provinceCode", provinceCode)
                .addParams("provinceName", provinceName)
                .addParams("cityCode", cityCode)
                .addParams("cityName", cityName)
                .addParams("townCode", townCode)
                .addParams("townName", townName)
                .addParams("surplusAddress", surplusAddress)
                .addParams("detailAddress", detailAddress)
                .addParams("postalCode", postalCode)
                .addParams("isTactly", isTactly)
                .build()
                .execute(callback);
    }

    /**
     * 查看地址信息列表
     * @param memberId 会员id
     * @param callback 回调
     */
    public static void findAddress(String memberId, RequestCallback
            callback) {
        String url = NetConfig.getBasicUrl() + "findAddress?" + "memberId="
                + memberId;

        OkHttpUtils.post()
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 发送请求，修改了默认地址
     * @param memberId 当前用户的empid
     * @param addressId 地址
     * @param callback 回调
     */
    public static void updateTactly(String memberId, String addressId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "updateTactly?";

        OkHttpUtils.post()
                .addParams("memberId", memberId)
                .addParams("addressId", addressId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 删除一条地址信息
     * @param addressId 地址
     * @param callback 回调
     */
    public static void deleteAddress(String addressId, RequestCallback
            callback) {
        String url = NetConfig.getBasicUrl() + "deleteAddress?";

        OkHttpUtils.post()
                .addParams("addressId", addressId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 查询所有订单数据
     * @param memberId 会员id
     * @param callback 回调
     */
    public static void findAllOrders(String memberId, RequestCallback
            callback) {
        String url = NetConfig.getBasicUrl() + "findAllOrders?";

        OkHttpUtils.post()
                .addParams("memberId", memberId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 直接购买添加订单
     * @param userId 用户id
     * @param productPrice 产品价格
     * @param productId 产品id
     * @param shoppingNumber 号码数字
     * @param receiveAddressId 接收地址
     * @param orderStatus 订购状态
     * @param callback 回调
     */
    public static void addOrderForDirect(String userId, String productPrice,
            String productId,
            String shoppingNumber,
            String receiveAddressId,
            String orderStatus,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "addOrderForDirect?";

//memberId=1111&productPrice=55&productId=11
// &shoppingNumber=44&receiveAddressId=22&orderStatus=333
        OkHttpUtils.post()
                .addParams("memberId", userId)
                .addParams("productPrice", productPrice)
                .addParams("productId", productId)
                .addParams("shoppingNumber", shoppingNumber)
                .addParams("receiveAddressId", receiveAddressId)
                .addParams("orderStatus", orderStatus)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 返回默认的地址
     * @param userId 用户id
     * @param callback 回调
     */
    public static void getDefaultAddress(String userId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "getDefaultAddress?";

        OkHttpUtils.post()
                .addParams("memberId", userId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 购物车购买添加订单
     * @param userId 用户id
     * @param receiveAddressId 接收地址
     * @param catIds 购物车id
     * @param callback 回调
     */
    public static void addOrderFromCat(String userId, String receiveAddressId, String catIds,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "addOrderFromCat?";

        OkHttpUtils.post()
                .addParams("memberId", userId)
                .addParams("receiveAddressId", receiveAddressId)
                .addParams("catIds", catIds)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 订单取消
     * @param orderId 订购id
     * @param cancleReason 取消原因
     * @param callback 回调
     */
    public static void cancleOrder(String orderId, String cancleReason,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() +
                "cancleOrder?";

        OkHttpUtils.post()
                .addParams("orderId", orderId)
                .addParams("cancleReason", cancleReason)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 申请退货
     * @param orderProductId 订购id
     * @param refundReason 退货理由
     * @param callback 回调
     */
    public static void requstRefund(String orderProductId, String refundReason, RequestCallback
            callback) {
        String url = NetConfig.getBasicUrl() + "requstRefund?";

        OkHttpUtils.post()
                .addParams("orderProductId", orderProductId)
                .addParams("refundReason", refundReason)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 商品退回时 发送用户填写的快递单号等数据
     * @param orderProductId 订单产品ID
     * @param expressCompany 快递公司名
     * @param expressNumber 快递单号
     * @param type 3  --> 退货       4  --> 换货
     * @param callback 回调
     */
    public static void goodSentBack(String orderProductId, String expressCompany, String
            expressNumber, String type, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "goodSentBack?";

        OkHttpUtils.post()
                .addParams("orderProductId", orderProductId)
                .addParams("expressCompany", expressCompany)
                .addParams("expressNumber", expressNumber)
                .addParams("type", type)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 发送请求；确认收货
     * @param orderId 订单id
     * @param callback 回调
     */
    public static void confirmRecipt(String orderId,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "confirmRecipt?";

        OkHttpUtils.post()
                .addParams("orderId", orderId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 申请换货
     * @param orderProductId 订购产品id
     * @param exchangeReason 异常原因
     * @param callback 回调
     */
    public static void requstExchange(String orderProductId, String exchangeReason,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "requstExchange?";

        OkHttpUtils.post()
                .addParams("orderProductId", orderProductId)
                .addParams("exchangeReason", exchangeReason)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 发表评价
     * @param orderId 订购id
     * @param memberId 会员id
     * @param evaluateLevel 评价水平
     * @param serviceLevel 服务水平
     * @param evaluateTitle 评价标题
     * @param callback 回调
     */
    public static void evaluate(String orderId,
            String memberId,
            String evaluateLevel,
            String serviceLevel,
            String evaluateTitle,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "evaluate?";
        OkHttpUtils.post()
                .addParams("orderId", orderId)
                .addParams("memberId", memberId)
                .addParams("evaluateLevel", evaluateLevel)
                .addParams("serviceLevel", serviceLevel)
                .addParams("evaluateTitle", evaluateTitle)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 查看退换货详情
     * @param orderProductId 订购id
     * @param callback 回调
     */
    public static void findAfterDetail(String orderProductId,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "findAfterDetail?";

        OkHttpUtils.post()
                .addParams("orderProductId", orderProductId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 取消退换货申请
     * @param orderProductId 订购产品id
     * @param callback 回调
     */
    public static void cancleRequest(String orderProductId,
            RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "cancleRequest?";

        OkHttpUtils.post()
                .addParams("orderProductId", orderProductId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 获取退换货寄回地址
     * @param orderProductId 订购id
     * @param callback 回调
     */
    public static void getSendBackAddr(String orderProductId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "getSentBackAddress?";
        OkHttpUtils.post()
                .addParams("orderProductId", orderProductId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 重新编辑退换货的理由
     * @param orderProductId 订购id
     * @param reason 原因
     * @param callback 回调
     */
    public static void updateRequestReason(String orderProductId, String reason, RequestCallback
            callback) {
        String url = NetConfig.getBasicUrl() + "updateRequestReason?";

        OkHttpUtils.post()
                .addParams("orderProductId", orderProductId)
                .addParams("reason", reason)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 根据用户ID查询EMP信息
     * @param userId 用户id
     * @param requestCallback 请求回调
     */
    public static void findEmployeeByUserId(String userId, RequestCallback requestCallback) {
        String url = NetConfig.getBasicUrl() + "findEmployeeByUserId";

        OkHttpUtils.post()
                .addParams("userId", userId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 根据用户ID查询用户信息
     * @param userId 用户id
     * @param requestCallback 请求回调
     */
    public static void findUserById(String userId, RequestCallback requestCallback) {
        String url = NetConfig.getBasicUrl() + "findUserById";

        OkHttpUtils.post()
                .addParams("userId", userId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 添加好友
     * @param contactUserId 联系人id
     * @param userId 用户id
     * @param requestId 请求id
     * @param callback 回调
     */
    public static void addContact(String contactUserId, String userId, String requestId,
            RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "addContact";

        OkHttpUtils.post()
                .addParams("contactUserId", contactUserId)
                .addParams("userId", userId)
                .addParams("requestId", requestId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 添加好友申请
     * @param callback 回调
     * @param bean bean数据
     */
    public static void addContactRequest(ContactRequestNetBean bean, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "saveContactRequest";

        OkHttpUtils.post()
                .addParams("requestUserId", bean.getRequestUserId())
                .addParams("targetUserId", bean.getTargetUserId())
                .addParams("mark", bean.getMark())
                .addParams("state", ContactRequestNetBean.STATE_WAIT)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 保存群组
     * @param groupId 群组id,消息主题
     * @param groupName 群组名称
     * @param userIds 用户id
     * @param groupPic 群头像
     * @param groupOwnerId 群主id
     * @param callback 回调
     */
    public static void saveGroup(String groupId, String groupName, String userIds, String
            groupPic, String groupOwnerId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "saveGroup";

        OkHttpUtils.post()
                .addParams("groupId", groupId)
                .addParams("groupName", groupName)
                .addParams("userIds", userIds)
                .addParams("groupPic", groupPic)
                .addParams("groupOwnerId", groupOwnerId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 查询单个群组
     * @param groupId 列的id
     * @param callback 回调
     */
    public static void findCommunityById(String groupId, RequestCallback callback) {

        String url = NetConfig.getBasicUrl() + "findCommunityById";

        OkHttpUtils
                .post()
                .addParams("groupId", groupId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 查询用户群组集合
     * @param userId 用户id
     * @return 响应数据
     * @throws Exception 异常
     */
    public static Response findCommunityGroup(String userId) throws Exception {
        String url = NetConfig.getBasicUrl() + "findCommunityGroup";

        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", userId);

        Request request = buildSyscPostRequest(url, params);

        OkHttpClient client = new OkHttpClient();
        return client.newCall(request).execute();
    }

    /**
     * 退出群组
     * @param groupId 群组id,消息主题
     * @param userId 用户id
     * @param callback 回调
     */
    public static void quiteGroup(String groupId, String userId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "quitGroup";

        OkHttpUtils.post()
                .addParams("groupId", groupId)
                .addParams("userId", userId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 确认加入群组
     * @param groupId 群组id,消息主题
     * @param userId 用户id
     * @param callback 回调
     */
    public static void jionGroup(String groupId, String userId, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "joinGroup";

        OkHttpUtils.post()
                .addParams("groupId", groupId)
                .addParams("userId", userId)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 修改用户信息
     * @param userId 用户id
     * @param nickName 昵称
     * @param realName 真实姓名
     * @param addr 地址
     * @param note 个性签名
     * @param callback 回调
     */
    public static void updateUserMsg(String userId, String nickName, String realName, String
            addr, String note, RequestCallback callback) {
        String url = NetConfig.getBasicUrl() + "updateUserMsg";

        OkHttpUtils.post()
                .addParams("userId", userId)
                .addParams("nickName", nickName)
                .addParams("realName", realName)
                .addParams("addr", addr)
                .addParams("note", note)
                .url(url)
                .build()
                .execute(callback);
    }

    /**
     * 修改用户头像
     * @param userId 用户id
     * @param picString 图片地址
     * @param requestCallback 请求回调
     */
    public static void updateUserHead(String userId, String picString, RequestCallback
            requestCallback) {
        String url = NetConfig.getBasicUrl() + "updateUserHead";
        OkHttpUtils.post()
                .addParams("userId", userId)
                .addParams("picString", picString)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 根据用户ID查询好友申请信息
     * @param userId 用户id
     * @param requestCallback 请求回调
     */
    public static void findRequestByUserId(String userId, RequestCallback
            requestCallback) {
        String url = NetConfig.getBasicUrl() + "findRequestByUserId";

        OkHttpUtils.post()
                .addParams("userId", userId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 根据订单编号查询订单信息
     * @param orderId 订购id
     * @param requestCallback 请求回调
     */
    public static void findOrderByOrderId(String orderId, RequestCallback requestCallback) {
        String url = NetConfig.getBasicUrl() + "findOrderByOrderId";

        OkHttpUtils.post()
                .addParams("orderId", orderId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 根据商品关系id查询商品信息
     * @param orderProductId 订购产品id
     * @param requestCallback 请求回调
     */
    public static void findOrderProById(String orderProductId, RequestCallback requestCallback) {
        String url = NetConfig.getBasicUrl() + "findOrderProById";
        OkHttpUtils.post()
                .addParams("id", orderProductId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 售后确认解决
     * @param serviceId 售后服务id
     * @param requestCallback 请求回调
     */
    public static void doSaleConfirm(String serviceId, RequestCallback requestCallback) {
        String url = NetConfig.getBasicUrl() + "doSaleConfirm";
        OkHttpUtils.post()
                .addParams("id", serviceId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 售后服务评价
     * @param serviceId 售后服务id
     * @param evaluateLevel 评价星级
     * @param evaluateContent 评价内容
     * @param requestCallback 请求回调
     */
    public static void doSaleEvaluate(String serviceId, String evaluateLevel, String
            evaluateContent, RequestCallback requestCallback) {
        String url = NetConfig.getBasicUrl() + "doSaleEvaluate";
        OkHttpUtils.post()
                .addParams("id", serviceId)
                .addParams("evaluateLevel", evaluateLevel)
                .addParams("evaluateTitle", evaluateContent)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 更新售后回复提醒状态
     * @param serviceId 售后服务id
     * @param requestCallback 请求回调
     */
    public static void updateReply(String serviceId, RequestCallback requestCallback) {
        String url = NetConfig.getBasicUrl() + "updateReply";
        OkHttpUtils.post()
                .addParams("id", serviceId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 删除好友
     * @param userId 用户id
     * @param contactUserId 联系人id
     * @param requestCallback 请求回调
     */
    public static void deleteContact(String userId, String contactUserId, RequestCallback
            requestCallback) {

        String url = NetConfig.getBasicUrl() + "deleteContact";

        OkHttpUtils.post()
                .addParams("userId", userId)
                .addParams("contactUserId", contactUserId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 删除订单
     * @param orderId 订单id
     * @param requestCallback 请求回调
     */
    public static void deleteOrder(String orderId, RequestCallback requestCallback) {
        String url = NetConfig.getBasicUrl() + "deleteOrder";

        OkHttpUtils.post()
                .addParams("orderId", orderId)
                .url(url)
                .build()
                .execute(requestCallback);
    }

    /**
     * 构建一个同步http请求
     * @param url 地址
     * @param params map集合
     * @return 返回同步请求对象
     */
    private static Request buildSyscPostRequest(String url, Map<String, String> params) {

        FormBody.Builder builder = new FormBody.Builder();
        if (params != null && !params.isEmpty()) {
            for (String key : params.keySet()) {
                builder.add(key, params.get(key));
            }
        }

        RequestBody requestBody = builder.build();
        return new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();
    }
}


